{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class ParentClass:\n",
    "    parent_variable = \"I am a parent variable\"\n",
    "\n",
    "    def __init__(self, parent_instance_variable):\n",
    "        self.parent_instance_variable = parent_instance_variable\n",
    "\n",
    "class ChildClass(ParentClass):\n",
    "    child_variable = \"I am a child variable\"\n",
    "\n",
    "    def __init__(self, parent_instance_variable, child_instance_variable):\n",
    "        super().__init__(parent_instance_variable)\n",
    "        self.child_instance_variable = child_instance_variable\n",
    "        \n",
    "child_obj = ChildClass(\"Parent instance variable\", \"Child instance variable\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "mappingproxy({'__module__': '__main__',\n",
       "              'child_variable': 'I am a child variable',\n",
       "              '__init__': <function __main__.ChildClass.__init__(self, parent_instance_variable, child_instance_variable)>,\n",
       "              '__doc__': None})"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ChildClass.__dict__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "查看对象的所有实例属性及其对应的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'parent_instance_variable': 'Parent instance variable',\n",
       " 'child_instance_variable': 'Child instance variable'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "child_obj.__dict__"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "grammer-study-12-env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
